#! /bin/sh

set -e

# Load debconf
. /usr/share/debconf/confmodule

CFG_FILE='/etc/fpc.cfg'
CFG_PRIORITY=$(echo ${VERSION} | sed -e 's/\.//g')

if test -f "${CFG_FILE}" && ! test -L "${CFG_FILE}"
then
	db_get fp-compiler${PACKAGESUFFIX}/rename_cfg
	if test "${RET}" = "true"
	then
		mv "${CFG_FILE}" "${CFG_FILE}.bak"
	fi
fi

# add alternatives
update-alternatives \
    --install /usr/bin/fpc fpc /usr/bin/fpc-${VERSION} 20 \
    --slave /usr/bin/${PPCBIN} ${PPCBIN} /usr/lib/fpc/${VERSION}/${PPCBIN} \
    --slave /usr/bin/fpc-depends fpc-depends /usr/bin/fpc-depends-${VERSION} \
    --slave /usr/share/man/man1/${PPCBIN}.1.gz ${PPCBIN}.1.gz /usr/share/man/man1/${PPCBIN}-${VERSION}.1.gz \
    --slave /usr/share/man/man1/fpc.1.gz fpc.1.gz /usr/share/man/man1/fpc-${VERSION}.1.gz \
    --slave /usr/share/man/man1/fpc-depends.1.gz fpc-depends.1.gz /usr/share/man/man1/fpc-depends-${VERSION}.1.gz
update-alternatives \
    --install /usr/bin/pc pc /usr/bin/fpc-${VERSION} 20 \
    --slave /usr/share/man/man1/pc.1.gz pc.1.gz /usr/share/man/man1/fpc-${VERSION}.1.gz

# Configuration file is a special case as it is backward compatible and is
# likely to be handled as a special alternative pointing to the latest release
update-alternatives \
	--install ${CFG_FILE} fpc.cfg /etc/fpc-${VERSION}.cfg ${CFG_PRIORITY}\

# Debhelper code
#DEBHELPER#
